﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telecom.Data;

namespace Telecom.Service
{
    public class UserQuyenHT_Ser
    {
        private readonly EntitiesTelecom dbContext = new EntitiesTelecom();

        public UserQuyenHT_Ser()
        {
            dbContext.Configuration.LazyLoadingEnabled = false;
            dbContext.Configuration.ProxyCreationEnabled = false;
        }

        public decimal UpdateQuyenUser(USER_QUYENHT entity)
        {
            dbContext.Entry(entity).State = System.Data.EntityState.Modified;
            dbContext.SaveChanges();
            return entity.ID;
        }

        public decimal addQuyenUser(USER_QUYENHT entity)
        {
            dbContext.USER_QUYENHT.Add(entity);
            dbContext.SaveChanges();
            return entity.ID;
        }

        public List<USER_QUYENHT> getList()
        {
            try
            {
                return dbContext.USER_QUYENHT.OrderBy(p => p.ID).ToList();
            }
            catch
            {
                return null;
            }
        }

        public List<USER_QUYENHT> getListByUserId(int userId)
        {
            try
            {
                return dbContext.USER_QUYENHT.Where(p => p.USERID == userId).OrderBy(p => p.ID).ToList();
            }
            catch
            {
                return null;
            }
        }

        public USER_QUYENHT GetById(int id)
        {
            try
            {
                return dbContext.USER_QUYENHT.Where(p => p.ID == id).First();
            }
            catch
            {
                return null;
            }
        }

        public bool detele(int id)
        {
            try
            {
                var _entity = GetById(id);
                dbContext.USER_QUYENHT.Remove(_entity);
                dbContext.SaveChanges();
                return true;
            }
            catch { return false; }
        }

       
    }
}
